package cn.tedu.tmall.admin.content.dao.repository.impl;


import cn.tedu.tmall.admin.content.dao.mapper.ArticleDetailMapper;
import cn.tedu.tmall.admin.content.dao.mapper.ArticleMapper;
import cn.tedu.tmall.admin.content.dao.repository.IArticleRepository;
import cn.tedu.tmall.admin.content.pojo.param.ArticleAddParam;
import cn.tedu.tmall.admin.content.pojo.po.ArticleDetailPO;
import cn.tedu.tmall.admin.content.pojo.po.ArticlePO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
@Slf4j
public class ArticleRepository implements IArticleRepository {
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ArticleDetailMapper articleDetailMapper;
    @Override
    public void add(ArticleAddParam articleAddParam) {
        ArticlePO articlePO = new ArticlePO();
        BeanUtils.copyProperties(articleMapper,articlePO);

    }

    @Override
    public Integer countArticleByTitle(String title) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("title",title);
        return articleMapper.selectCount(queryWrapper);
        }


    @Override
    public Integer saveArticleDetail(ArticleDetailPO articleDetailPO) {
        return articleDetailMapper.insert(articleDetailPO);
    }

    @Override
    public Integer saveArticle(ArticlePO articlePO) {
        return  articleMapper.insert(articlePO);
    }
}
